﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace MortEdit
{
    // Rozszerzona klasa RichTextBox'a
    // Posiada implementację podświetlania składni
    public class RichTextBoxExtended : RichTextBox
    {
        // tworzenie obiektu podświetlacza składni.
        private SyntaxHighlighting SyntaxHighlighter = new SyntaxHighlighting();

        // dodanie nowych właściwości:
        private List<string> keywordsList = new List<string>();
        public List<string> commentsCharList = new List<string>();

        public Color keywordsColor = Color.Blue;
        public Color commentsColor = Color.Red;
        public Color stringsColor = Color.Green;
        public Color numbersColor = Color.DarkRed;

        // dodanie nowego eventa:
        public event EventHandler CursorPositionChanged;

        // dodanie KeywordsList do properties
        [Browsable(true), Category("Extended"), Description("Gets or Sets the keywords used for syntax highlightning")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public List<string> KeywordsList
        {
            get { return keywordsList; }
            set { keywordsList = value; }
        }

        // dodanie CommentsChars do properties
        [Browsable(true), Category("Extended"), Description("Gets or Sets the comments chars for syntax highlighting.")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public List<string> CommentsChars
        {
            get { return commentsCharList; }
            set { commentsCharList = value; }
        }

        [Browsable(true), Category("Extended"), Description("Gets or Sets the color for keywords highlighting.")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public Color KeywordsColor
        {
            get { return keywordsColor; }
            set { keywordsColor = value; }
        }

        [Browsable(true), Category("Extended"), Description("Gets or Sets the color for comments highlighting.")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public Color CommentsColor
        {
            get { return commentsColor; }
            set { commentsColor = value; }
        }

        [Browsable(true), Category("Extended"), Description("Gets or Sets the color for strings highlighting.")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public Color StringsColor
        {
            get { return stringsColor; }
            set { stringsColor = value; }
        }

        [Browsable(true), Category("Extended"), Description("Gets or Sets the color for numbers highlighting.")]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        public Color NumbersColor
        {
            get { return numbersColor; }
            set { numbersColor = value; }
        }

        // jeśli pozycja kursora się zmieniła
        protected virtual void OnCursorPositionChanged(EventArgs e)
        {
            if (CursorPositionChanged != null)
                CursorPositionChanged(this, e);
        }

        // jeśli zmieniło się zaznaczenie
        protected override void OnSelectionChanged(EventArgs e)
        {
            if (SelectionLength == 0)
                OnCursorPositionChanged(e);
            else
                base.OnSelectionChanged(e);
        }

        public int CurrentColumn
        {
            get
            {
                return RichTextBoxExtendedHelper.CurrentColumn(this, SelectionStart);
            }
        }

        public int CurrentLine
        {
            get
            {
                return RichTextBoxExtendedHelper.CurrentLine(this, SelectionStart);
            }
        }

        public int CurrentPosition
        {
            get
            {
                return this.SelectionStart;
            }
        }

        public void UpdateSyntaxHightlight()
        {
            SyntaxHighlighter.HightlightAllLines(this);
        }
    }

    

}
